#!/bin/bash


PATH=/bin:/usr/bin:/usr/sbin:/opt/bind/bin

if [ "X$1" == "X-h" -o "X$1" == "X--help" ]; then
	echo "
	$(basename $0)	Verify a forward zone by quering the zone on its remote servers

	Usage: $(basename $0) [zone:server[/server[/server]...]]
	
	/etc/named/nodb.zones is read if no zone/server specified
" >&2
	exit 1
fi

if [ "X$1" == "X" ]; then
	nodb=$(/usr/local/sbin/zonecat -T /etc/named/nodb.zones | awk '$2 == "forward" {print $1 ":" $3}')
else
	nodb=$1
fi

for l in $(echo $nodb); do 
	zone=$(echo $l | sed -e "s/:.*//")
	servers=$(echo $l | sed -e "s/.*://" -e "s/\// /g")
	for server in $(echo $servers); do
		echo -e "Querying SOA record of Zone \"$zone\" on Server \"$server\" via ..."
		echo -e "	53/TCP: \t\c"; dig @${server} -t soa $zone +short +tcp
		echo -e "	53/UDP: \t\c"; dig @${server} -t soa $zone +short +notcp
	done
	echo
done
